package com.gxa.insurance.controller;

import com.gxa.insurance.exception.BusinessException;
import com.gxa.insurance.pojo.Order;
import com.gxa.insurance.pojo.OrderStatus;
import com.gxa.insurance.pojo.Salary;
import com.gxa.insurance.service.OrderService;
import com.gxa.insurance.service.OrderStatusService;
import com.gxa.insurance.service.SalaryService;
import com.gxa.insurance.util.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @date 2022/6/16
 */
@Api(value = "司机端的还车api接口")
@RestController
@RequestMapping("/OrderStatus")
@CrossOrigin
public class OrderStatusController {

    @Autowired
    OrderStatusService orderStatusService;

    @ApiOperation("按照订单状态,获取订单状态表的id,用于修改order中的订单状态")
    @ApiImplicitParam(name = "orderStatus",value = "订单状态",paramType = "query")
    @PostMapping("/selectOrderStatus")
    public Map selectOrderStatus(String orderStatus) throws BusinessException {

        OrderStatus orderStatus1 = orderStatusService.selectOrderStatus(orderStatus);

        JsonResult jsonResult =new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setMsg("查询成功");
        jsonResult.setData(orderStatus1);

        return  jsonResult.getMap();
    }


    @Autowired
    SalaryService salaryService;
    @ApiOperation("添加司机工资")
    @PostMapping("/addStatus")
    @Transactional
    public Map addStatus(@RequestBody Salary salary
//                         ,@RequestBody Order order
    ) throws BusinessException {

//        orderStatusService.updateStatus(order);


        Integer integer = salaryService.insertSalaryMessage(salary);


        JsonResult jsonResult =new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setMsg("添加成功");
        jsonResult.setData(integer);

        return  jsonResult.getMap();

    }


    @ApiOperation("修改订单状态")
    @PostMapping("/updateStatus")
    public Map updateStatus(@RequestBody Order order){

        orderStatusService.updateStatus(order);



        JsonResult jsonResult =new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setMsg("修改订单状态成功");

        return  jsonResult.getMap();

    }
}
